<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue2-01-快速入门</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<style>
    * {
        box-sizing: border-box;
    }

    body {
        background-color: #222;
        color: snow;
    }

    a {
        color: snow;
    }
</style>
<body>
<div id="app">
    <h1>Vue2-01-快速入门</h1>
    <div>
        <h2>v-model与v-bind指令：绑定表单与属性</h2>
        <input type="text" v-model="message">
        {{ message }}
        <hr>
        <a v-bind:href="url">双向绑定的URL</a>
        <input type="text" v-model="url" style="width: 15rem;">
    </div>
    <div>
        <h2>v-on指令：绑定事件</h2>
        <button @click="showMsg">click事件绑定showMsg方法的按钮</button>
    </div>
    <div>
        <h2>v-if、v-else-if和v-else指令：条件渲染</h2>
        年龄 <input type="text" v-model="age">，经判定为
        <span v-if="age<=35">年轻人（35及以下）</span>
        <span v-else-if="age>35&&age<60">中年人（35到60）</span>
        <span v-else>老年人（60以上）</span>
    </div>
    <div>
        <h2>v-show指令：条件显示</h2>
        年龄小于18时才会显示：<span v-show="age<18">未成年</span>
    </div>
    <div>
        <h2>v-for指令：迭代渲染</h2>
        <span v-for="addr in addrs">{{ addr }} </span>
        <hr>
        <span v-for="(addr, index) in addrs">{{ index }}. {{ addr }} </span>
    </div>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue2!',
            url: 'https://www.bilibili.com/',
            age: 18,
            addrs: ['北京', '上海', '广州', '深圳'],
        },
        methods: {
            showMsg: function () {
                alert('Hello Vue2!');
            },
        },
    });
</script>
</body>
</html>